﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NUnitResults
{
    public class FailedTestCase : TestCase
    {
        public String Message { get; private set; }

        public String StackTrace { get; private set; }

        public FailedTestCase(String name, String nspace, Status status, Nullable<TimeSpan> time, Nullable<Int32> asserts, String message, String stackTrace)
            : base(name, nspace, status, time, asserts)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (stackTrace == null)
            {
                throw new ArgumentNullException("stackTrace");
            }

            Message = message;
            StackTrace = stackTrace;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode() ^ Message.GetHashCode() ^ StackTrace.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            var other = obj as FailedTestCase;

            if (other == null)
            {
                return false;
            }

            if (!base.Equals(other))
            {
                return false;
            }

            if (this.Message != other.Message)
            {
                return false;
            }

            if (this.StackTrace != other.StackTrace)
            {
                return false;
            }

            return true;
        }

        /// <summary>
        /// Converts this test case to a string.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return String.Format("TestCase(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\")", Name, Namespace, Status, Message, StackTrace);
        }
    }
}
